package com.ysm.smfu.food;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.ysm.smfu.R;
import com.ysm.smfu.activity.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/4/11.
 */
public class ZhiFuFoodActivity extends BaseActivity {
    @BindView(R.id.img)
    ImageView img;
    @BindView(R.id.price)
    TextView price;
    @BindView(R.id.food_title)
    TextView foodTitle;
    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.yuerZhiFu)
    CheckBox yuerZhiFu;
    @BindView(R.id.wxZhiFu)
    CheckBox wxZhiFu;
    @BindView(R.id.aliZhiFu)
    CheckBox aliZhiFu;
    @BindView(R.id.submit)
    TextView submit;

    @Override
    protected void initViews() {
        super.initViews();
        setContentView(R.layout.activity_food_zhifu);
        ButterKnife.bind(this);
        title.setText("支付订单");
    }

    @Override
    protected void initData() {
        super.initData();
        Intent intent = getIntent();
        int foodPrice = intent.getIntExtra("foodPrice",0);
        String foodtitle = intent.getStringExtra("foodTitle");
        String foodUrl = intent.getStringExtra("foodUrl");
        if (!TextUtils.isEmpty(foodUrl) && !foodUrl.startsWith("null?"))
            Glide.with(this).load(foodUrl).into(img);
        price.setText(String.valueOf(foodPrice));
        submit.setText("确认提交:￥" + String.valueOf(foodPrice));
        foodTitle.setText(foodtitle);
    }

    List<CheckBox> list = new ArrayList<>();

    @Override
    protected void initListener() {
        super.initListener();
        list.add(yuerZhiFu);
        list.add(wxZhiFu);
        list.add(aliZhiFu);
    }

    @OnClick({R.id.back, R.id.submit, R.id.yuerZhiFu, R.id.wxZhiFu, R.id.aliZhiFu})
    public void onclick(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.yuerZhiFu:
                setCheckBox(0);
                break;
            case R.id.wxZhiFu:
                setCheckBox(1);
                break;
            case R.id.aliZhiFu:
                setCheckBox(2);
                break;
            case R.id.submit://提交
                submit();
                break;
        }
    }

    /**
     * 提交支付
     */
    private void submit() {
        int checkBox = getCheckBox();
        if (checkBox == 0)//余额支付
        {
        } else if (checkBox == 1)//微信支付
        {
        } else if (checkBox == 2)//支付宝支付
        {
        }

    }

    /**
     * 设置支付方式
     *
     * @param j
     */
    public void setCheckBox(int j) {
        for (int i = 0; i < list.size(); i++) {
            if (i == j) {
                list.get(i).setChecked(true);
            } else
                list.get(i).setChecked(false);
        }
    }

    public int getCheckBox() {
        for (int i = 0; i < list.size(); i++) {
            CheckBox checkBox = list.get(i);
            if (checkBox.isChecked())
                return i;
        }
        return -1;
    }
}
